#include "elisa/elisa.h"
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <gaol/gaol>

#include "Modeler.h"

#ifdef ELISA_PERFORMER
#include "elisa_chrono.h"
#endif

using namespace std;
using namespace elisa;

class Horn : public Modeler
{
private:
	Model _model;

	RealConstant r;
	RealConstant c;
	RealVar x;
	RealVar y;
	RealConstraint c1;
	RealConstraint c2;

public:
	Horn()
		: r(10),
		  c(0),
		  x(Interval(-2.0, 2.0), "x"),
		  y(Interval(-3.0, 3.0), "y"),
		  //c1(x == y),
		  c1((pow(x, 6)/4 - 1.9 * pow(x, 5) + 0.25 * pow(x, 4), + 20 * pow(x, 3) 
			- 17 * pow(x, 2) - 55.6 * x + 48) / 50.0 == y)
		  //c2(x == r),
		  //_model(c1)
	{
	}

	void init(int c)
	{
		x.reset();
		x.setDomain(new Interval(0, 5.0));
		y.reset();
		y.setDomain(new Interval(0, 5.0));
		c1.reset();
	}

	elisa::Model & model()
	{
		_model = c1 && c2;
		return _model;
	}

	void print()
	{
		cout << '\t' << x.getName() << " = " << x.domain() << endl;
		cout << '\t' << y.getName() << " = " << y.domain() << endl;
		cout << '\t' << "r = " << r.getInterval() << endl;

		static ofstream fo("sol0.log");
		printAsRect(fo, x.domain(), y.domain());
		//fo << x.domain().mid() << " " << y.domain().mid() << endl;
	}

	RealVar & varX()
	{
		return x;
	}
	RealVar & varY()
	{
		return y;
	}
};
